# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=sofia-sip
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=4438.f5ee2e0
pkgrel=1
pkgdesc="SIP User-Agent library (git) (mingw-w64)"
arch=('any')
url="https://sofia-sip.sourceforge.io/"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             'git')
depends=()
options=('strip' 'staticlibs')
source=("${_realname}"::"git+https://github.com/BelledonneCommunications/sofia-sip.git#branch=master"
        "0001-add-mingw-support.patch"
        "0002-su-select-port.patch"
        "0003-inet-pton-ntop-fix.patch"
        "0004-add-su_win32_port.patch"
        "0005-add-no-undefined-flag.patch")
sha256sums=('SKIP'
            '676e88b71984d408bd123bb6398e2ae524fae0a3d958d62b6c97e8a97aab05cc'
            'c8e6b43d02f0c23c1ef2a7d85124d88e1f705875ed9ddb00658e13c79f73874e'
            '1fdc83fad907ce82f9f099caaa0cbea282302bf33fdaeef581aed4d2486da201'
            'eac5b7f796e4d05f8f208e7d26bb7a4f7350c046b5f7393ee21fe9aab1f25f67'
            'f4e54a7c910c59c0da5922c16dab6142a5d94c8e2bc52b3790abd6f74afa925e')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  patch -p2 -i "${srcdir}"/0001-add-mingw-support.patch
  patch -p2 -i "${srcdir}"/0002-su-select-port.patch
  patch -p2 -i "${srcdir}"/0003-inet-pton-ntop-fix.patch
  patch -p2 -i "${srcdir}"/0004-add-su_win32_port.patch
  patch -p2 -i "${srcdir}"/0005-add-no-undefined-flag.patch
}

build() {
  cd "$srcdir"/${_realname}
  autoreconf -i
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR=${pkgdir} install-strip
}
